/*
 * AuthTestPanel.cpp
 *
 *  Created on: 2012-11-3
 *      Author: tutu
 */

#include "AuthTestPanel.h"
#include "../TContext.h"
#include <QMessageBox>

AuthTestPanel::AuthTestPanel(QWidget *parent) : QWidget(parent)
{
	_heartbeatButton = new QPushButton(this);
	_heartbeatButton->setText("Heartbeat");
	_heartbeatButton->setGeometry(10, 10, 100, 30);
	connect(_heartbeatButton, SIGNAL(clicked()), this, SLOT(heartbeatButtonClicked()));

	_logoutButton = new QPushButton(this);
	_logoutButton->setText("Logout");
	_logoutButton->setGeometry(10, 50, 100, 30);
	connect(_logoutButton, SIGNAL(clicked()), this, SLOT(logoutButtonClicked()));

	_authRequester = TContext::instance()->requesterFactory()->createAuthRequester();
	connect(_authRequester.data(), SIGNAL(heartbeatFinished(bool)), this, SLOT(heartbeatFinished(bool)));
	connect(_authRequester.data(), SIGNAL(logoutFinished(bool)), this, SLOT(logoutFinished(bool)));
}

AuthTestPanel::~AuthTestPanel()
{
	// TODO Auto-generated destructor stub
}

void AuthTestPanel::heartbeatButtonClicked()
{
	_authRequester->heartbeat();
}

void AuthTestPanel::logoutButtonClicked()
{
	_authRequester->logout();
}

void AuthTestPanel::heartbeatFinished(bool error)
{
	if(!error)
		QMessageBox::warning(NULL, "Result", "Auth Success.");
	else
		QMessageBox::warning(NULL, "Result", "Auth Failure.");
}

void AuthTestPanel::logoutFinished(bool error)
{
	if(!error)
		QMessageBox::warning(NULL, "Result", "Logout Success.");
	else
		QMessageBox::warning(NULL, "Result", "Logout Failure.");
}

